package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.cache.key.RedisKey;
import cn.wolfcode.luowowo.cache.service.IVerifyCodeService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

@Service
public class VerifyCodeServiceImpl implements IVerifyCodeService{

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void setVerifyCode(String phone, String verifyCode) {
        //设计key-value

        String cacheKey = RedisKey.VERIFY_CODE.getCacheKey(phone);
        //获取redis对象,并保存,设置有效时间  , 单位毫秒
        stringRedisTemplate.opsForValue().set(cacheKey,verifyCode,RedisKey.VERIFY_CODE.getTimeout(), TimeUnit.MILLISECONDS);

    }

    public String getVerifyCode(String phone) {

        String cacheKey = RedisKey.VERIFY_CODE.getCacheKey(phone);
        return stringRedisTemplate.opsForValue().get(cacheKey);
    }



}
